package com.dayouzi.crawler_monitor.service.impl;

import com.dayouzi.crawler_monitor.base.exception.Assert;
import com.dayouzi.crawler_monitor.base.result.ResponseEnum;
import com.dayouzi.crawler_monitor.mapper.UserAdminMapper;
import com.dayouzi.crawler_monitor.pojo.entity.UserAdmin;
import com.dayouzi.crawler_monitor.pojo.page.PageBean;
import com.dayouzi.crawler_monitor.pojo.query.UserAdminQuery;
import com.dayouzi.crawler_monitor.pojo.vo.UserAdminVO;
import com.dayouzi.crawler_monitor.service.UserAdminService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DaYouZi
 * @since 2023-03-06
 */
@Service
@Slf4j
public class UserAdminServiceImpl implements UserAdminService {

    @Autowired
    private UserAdminMapper userAdminMapper;

    @Override
    public UserAdminVO getInfoById(Integer id) {
        return userAdminMapper.getInfoById(id);
    }

    @Override
    public Boolean foreverRemove(Integer id) {
        return userAdminMapper.foreverRemove(id);
    }

    @Override
    public Boolean updateInfoById(UserAdminQuery userAdminQuery) {
        return userAdminMapper.updateInfoById(userAdminQuery);
    }

    @Override
    public Boolean insertUserInfo(UserAdminQuery userAdminQuery) {
        String userName = userAdminQuery.getUserName();
        UserAdmin userAdmin = userAdminMapper.getInfoByUserName(userName);

        //判断用户是否存在
        Assert.isNull(userAdmin, ResponseEnum.LOGIN_USER_EXISTS);

        return userAdminMapper.insertUserInfo(userAdminQuery);
    }

    @Override
    public PageBean<UserAdminVO> listPage(Integer page, Integer limit, UserAdminQuery userAdminQuery) {
        PageHelper.startPage(page, limit);
        List<UserAdminVO> list = userAdminMapper.listPage(userAdminQuery);
        return new PageBean<>(list);
    }


    @Override
    public void setNoticeStatus(Integer userId) {
        userAdminMapper.setNoticeStatus(userId);
    }
}
